#include <Keyboard.h>
#include <Mouse.h>

char inByte = 0; 
char s = '1';

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Keyboard.begin();
  Mouse.begin();

//  Mouse.move(-40, 0);  //左移40
//
//  Mouse.move(40, 0);   //右移40
//  Mouse.click(MOUSE_LEFT); //左键按下
}

void loop() {
  if (Serial.available() > 0) 
  {
    inByte = Serial.read();
    // put your main code here, to run repeatedly:
     Keyboard.press(inByte);    //向电脑发送向左按键按下的指令
     delay(10);    
     Keyboard.releaseAll();    //向电脑发送按键释放的指令   
    Serial.println(inByte);    
    delay(10); 

    Mouse.move(-10, 0);  //左移10
    Mouse.click(MOUSE_LEFT); //左键按下
    delay(10); 
    
  }else{
    Serial.println("init"); 
    delay(2000);
  }
}



void serialKeyboard(){
  if (Serial.available() > 0) 
  {
    inByte = Serial.read();
    if(inByte == '0'){
      s = '0';
    }else if(inByte == '1'){
      s = '1';
    }
  }
  Serial.println(inByte);     
  Serial.println("inByte");    
  delay(1000);
  if(s == '0'){
      // put your main code here, to run repeatedly:
       Keyboard.press('a');    //向电脑发送向左按键按下的指令
       delay(50);    
       Keyboard.releaseAll();    //向电脑发送按键释放的指令       
    }
    delay(1000);
}
